<template>
  <div class="app">
    <a-breadcrumb style="margin-bottom: 10px">
      <a-breadcrumb-item>商家管理/处罚信息</a-breadcrumb-item>
    </a-breadcrumb>
    <a-row class="pd20 mt20">
      <a-col :span="6">
        商家名称：
        <a-input placeholder="请输入" v-model="queryForm.merchantName" />
      </a-col>
      <a-col :span="6">
        经营者姓名：
        <a-input placeholder="请输入" v-model="queryForm.operatorName" />
      </a-col>
      <a-col :span="6">
        经营者联系方式：
        <a-input placeholder="请输入" v-model="queryForm.operatorContact" />
      </a-col>
      <a-col :span="6">
        违规行为：
        <a-select v-model="queryForm.violationType" placeholder="请选择">
          <a-select-option
            v-for="(item, index) in violationList"
            :key="index"
            :value="item.dictValue"
          >
            {{ item.dictLabel }}
          </a-select-option>
        </a-select>
      </a-col>
      <a-col :span="6">
        处罚决定人：
        <a-input placeholder="请输入" v-model="queryForm.decisionMaker" />
      </a-col>
      <a-col :span="6">
        处罚执行人：
        <a-input placeholder="请输入" v-model="queryForm.executor" />
      </a-col>
      <a-col :span="8">
        创建时间范围：
        <a-range-picker
          style="width: 200px"
          @change="onChange"
          v-model="dateRange"
          :placeholder="['开始日期', '结束日期']"
        />
      </a-col>
      <a-col :span="4">
        <a-button type="primary" @click="handleSearch"> 查询 </a-button>&emsp;&nbsp;
        <a-button @click="cleanQuery">重置</a-button>
      </a-col>
    </a-row>
    <a-row class="pd20 mt20">
      <div class="btn_box">
        <div>处罚信息</div>
        <a-button
          type="primary"
          @click="addFn"
          v-hasPermi="['zhonghe:lxzz:add']"
          >添加</a-button
        >
      </div>
      <a-spin :spinning="loading">
        <div class="table-container">
          <a-table
            :columns="columns"
            :data-source="tableData"
            :pagination="false"
          >
            <template slot="description" slot-scope="text, record">
              <ToolTip :text="text" />
            </template>
            <template slot="operatorContact" slot-scope="text, record">
              <div class="phone-cell">
                <span>{{
                  record.showPhone ? text : $desensitizePhone(text)
                }}</span>
                <a-icon
                  :type="record.showPhone ? 'eye-invisible' : 'eye'"
                  @click.stop="togglePhoneVisibility(record)"
                />
              </div>
            </template>
            <span slot="action" slot-scope="text, record">
              <a
                @click="editFn(text, record)"
                v-hasPermi="['zhonghe:lxzz:edit']"
                >修改</a
              >
              <a-divider type="vertical" />
              <a
                @click="delFn(text, record)"
                v-hasPermi="['zhonghe:lxzz:del']"
                class="red"
                >删除</a
              >
            </span>
          </a-table>
        </div>

        <div class="page_box">
          <a-pagination
            v-model="queryForm.offset"
            :page-size-options="['20', '30', '40', '50']"
            :total="total"
            show-size-changer
            :page-size="queryForm.current"
            @showSizeChange="onShowSizeChange"
            @change="pageChange"
            :show-total="(total) => `共 ${total} 条`"
          ></a-pagination>
        </div>
      </a-spin>
    </a-row>
    <a-modal
      title="处罚信息配置"
      :visible="dialogVisible"
      width="38%"
      ok-text="确认"
      cancel-text="取消"
      @cancel="dialogVisible = false"
      @ok="putDict"
    >
      <a-form :form="form">
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="组织名称"
        >
          <a-input
            v-decorator="[
              'twoNewOrganizationName',
              { rules: [{ required: true, message: '请输入组织名称' }] },
            ]"
            placeholder="请输入组织名称"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="组织类型"
        >
          <a-select
            style="width: 120px"
            v-decorator="[
              'twoNewOrganizationType',
              { rules: [{ required: true, message: '请选择组织类型' }] },
            ]"
            placeholder="请选择组织类型"
          >
            <a-select-option
              v-for="(item, index) in typeList"
              :key="index"
              :value="item.value"
            >
              {{ item.label }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="组织地址"
        >
          <a-input
            v-decorator="[
              'twoNewOrganizationAddr',
              { rules: [{ required: true, message: '请输入组织地址' }] },
            ]"
            placeholder="请输入组织地址"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="法定代表人"
        >
          <a-input
            v-decorator="[
              'lawPerson',
              { rules: [{ required: true, message: '请输入法定代表人' }] },
            ]"
            placeholder="请输入法定代表人"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="联系方式"
        >
          <a-input
            v-decorator="[
              'lawPhone',
              { rules: [{ required: true, message: '请输入联系方式' }] },
            ]"
            placeholder="请输入联系方式"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="组织状态"
        >
          <a-select
            style="width: 120px"
            v-decorator="[
              'status',
              { rules: [{ required: true, message: '请选择组织类型' }] },
            ]"
            placeholder="请选择组织类型"
          >
            <a-select-option
              v-for="(item, index) in statusList"
              :key="index"
              :value="item.value"
            >
              {{ item.label }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="注册日期"
        >
          <a-date-picker
            v-decorator="[
              'registerTime',
              { rules: [{ required: true, message: '请选择注册日期' }] },
            ]"
            placeholder="请选择注册日期"
            format="YYYY-MM-DD"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="成立日期"
        >
          <a-date-picker
            v-decorator="[
              'pushTime',
              { rules: [{ required: true, message: '请选择成立日期' }] },
            ]"
            placeholder="请选择成立日期"
            format="YYYY-MM-DD"
          />
        </a-form-item>
        <a-form-item
          :label-col="formItemLayout.labelCol"
          :wrapper-col="formItemLayout.wrapperCol"
          label="业务范围"
        >
          <a-input
            v-decorator="[
              'businessType',
              { rules: [{ required: true, message: '请输入检查结果' }] },
            ]"
            placeholder="请输入检查结果"
          />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
import { message, Modal } from "ant-design-vue";
import dayjs from "dayjs";
export default {
  data() {
    return {
      dateRange: "",
      loading: true,
      dialogVisible: false,
      queryForm: { current: 20, offset: 1 },
      violationType: "",
      total: 0,
      form: this.$form.createForm(this, { name: "coordinated" }),
      id: null,
      tableData: [],
      violationList: [],
      penaltyList: [],
      columns: [
        {
          title: "处罚ID",
          dataIndex: "penaltyInfoId",
          key: "penaltyInfoId",
          width: "100px",
        },
        {
          title: "关联商家ID",
          dataIndex: "merchantId",
          key: "merchantId",
          width: "100px",
        },
        {
          title: "商家名称",
          dataIndex: "merchantName",
          key: "merchantName",
          width: "100px",
          scopedSlots: { customRender: "description" },
        },
        {
          title: "商家位置",
          dataIndex: "road",
          key: "road",
          width: "100px",
        },
        {
          title: "实际经营项目",
          dataIndex: "actualBusinessItems",
          key: "actualBusinessItems",
          width: "110px",
          scopedSlots: { customRender: "description" },
        },
        {
          title: "经营者姓名",
          dataIndex: "operatorName",
          key: "operatorName",
          width: "100px",
        },
        {
          title: "经营者联系方式",
          dataIndex: "operatorContact",
          key: "operatorContact",
          scopedSlots: { customRender: "operatorContact" },
          width: 150,
        },
        {
          title: "违规行为",
          dataIndex: "violationType",
          key: "violationType",
          width: "100px",
          customRender: (text) => {
            let findOne = this.violationList.find(
              (item) => item.dictValue == text
            );
            return findOne && findOne.dictLabel;
          },
        },
        {
          title: "处罚依据",
          dataIndex: "legalBasis",
          key: "legalBasis",
          width: "100px",
          customRender: (text) => {
            let findOne = this.penaltyList.find(
              (item) => item.dictValue == text
            );
            return findOne && findOne.dictLabel;
          },
        },
        {
          title: "处罚决定人",
          dataIndex: "decisionMaker",
          key: "decisionMaker",
          width: "100px",
        },
        {
          title: "处罚执行人",
          dataIndex: "executor",
          key: "executor",
          width: "100px",
        },
        {
          title: "创建人",
          dataIndex: "createdByName",
          key: "createdByName",
          width: "100px",
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          key: "createTime",
          width: "100px",
        },
        {
          title: "操作",
          key: "action",
          width: "120px",
          fixed: "right",
          scopedSlots: { customRender: "action" },
        },
      ],
      formItemLayout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 19 },
      },
      formTailLayout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 19, offset: 4 },
      },
      typeList: [
        {
          value: "1",
          label: "非公有经济组织",
        },
        {
          value: "2",
          label: "公有经济组织",
        },
      ],
      statusList: [
        {
          value: 0,
          label: "正常",
        },
        {
          value: 1,
          label: "异常",
        },
        {
          value: 2,
          label: "停业",
        },
      ],
    };
  },
  async mounted() {
    await this.getDictList();
    await this.getList();
  },
  methods: {
    handleSearch(){
      this.queryForm.offset = 1;
      this.getList();
    },
    getDictList() {
      this.$axios
        .get(
          "/government-platform-center/dictData/queryByCode?dictType=VIOLATION_BEHAVIOR"
        )
        .then((res) => {
          if (res.data.code == 0) {
            this.violationList = res.data.data.map((item) => {
              item["showPhone"] = false;
              return item;
            });
          }
        });
      this.$axios
        .get(
          "/government-platform-center/dictData/queryByCode?dictType=PENALTY_BASIS"
        )
        .then((res) => {
          if (res.data.code == 0) {
            this.penaltyList = res.data.data;
          }
        });
    },
    getList() {
      this.loading = true;
      const url = "/government-platform-center/xunjian/penaltyInfo/queryByPage";
      const data = this.queryForm;
      this.$axios.post(url, data).then((res) => {
        if (res.data.code == 0) {
          this.tableData = res.data.data;
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },
    cleanQuery() {
      this.queryForm = { current: 20, offset: 1 };
      this.dateRange = "";
      this.getList();
    },
    // 分页
    onShowSizeChange(current, pageSize) {
      this.queryForm.current = pageSize;
      this.queryForm.offset = 1;
      this.getList();
    },
    pageChange(current) {
      this.queryForm.offset = current;
      this.getList();
    },
    delFn(text, record) {
      const that = this;
      Modal.confirm({
        title: "确认删除",
        content: "您确定要删除这项内容吗？",
        okText: "确认",
        cancelText: "取消",
        onOk() {
          console.log(text);
          const url = `/government-platform-center/xunjian/penaltyInfo/delete?penaltyInfoId=${text.penaltyInfoId}`;
          that.$axios.delete(url).then((res) => {
            if (res.data.code == 0) {
              that.getList();
              message.success("删除成功");
            }
          });
        },
        onCancel() {
          // 在此处理取消逻辑
          console.log("删除已取消");
        },
      });
    },
    goData(text, record) {
      this.$router.push({
        path: "/dataDict",
        query: { dictType: text.dictType, id: text.id },
      });
    },
    addFn() {
      this.$router.push({ path: "/xuncha/sjgl/addcf" });
    },
    editFn(text, record) {
      this.$router.push({
        path: "/xuncha/sjgl/addcf",
        query: {
          type: "edit",
          penaltyInfoId: text.penaltyInfoId,
        },
      });
    },
    putDict() {
      this.form.validateFields((err, values) => {
        if (err) {
          return;
        }
        if (!this.id) {
          const form = values;
          form.registerTime = dayjs(form.registerTime).format("YYYY-MM-DD");
          form.pushTime = dayjs(form.pushTime).format("YYYY-MM-DD");
          const url = "/government-platform-center/twoNewOrganization";
          this.$axios
            .post(url, form, {
              headers: {
                "Content-Type": "application/x-www-form-urlencoded",
              },
            })
            .then((res) => {
              if (res.data.code == 0) {
                this.getList();
                this.reSetForm();
                this.dialogVisible = false;
                message.success("操作成功");
              }
            });
        } else {
          const form = { ...values, id: this.id };
          form.registerTime = dayjs(form.registerTime).format("YYYY-MM-DD");
          form.pushTime = dayjs(form.pushTime).format("YYYY-MM-DD");
          const url = "/government-platform-center/twoNewOrganization/edit";
          this.$axios
            .post(url, form, {
              headers: {
                "Content-Type": "application/x-www-form-urlencoded",
              },
            })
            .then((res) => {
              if (res.data.code == 0) {
                this.getList();
                this.reSetForm();
                this.dialogVisible = false;
                message.success("操作成功");
              }
            });
        }
      });
    },
    reSetForm() {
      // this.form = { dictName: null, dictType: null, remark: null }
    },
    onChange() {
      this.queryForm.startTime = dayjs(this.dateRange[0]["_d"]).format(
        "YYYY-MM-DD"
      );
      this.queryForm.endTime = dayjs(this.dateRange[1]["_d"]).format(
        "YYYY-MM-DD"
      );
    },
    togglePhoneVisibility(record) {
      this.$set(record, "showPhone", !record.showPhone);
    },
  },
};
</script>

<style lang="scss" scoped>
.ant-row {
  border-radius: 5px;

  background: #fff;
  color: #000;
}

v-deep {
  .ant-table-thead > tr > th {
    color: #000;
    font-weight: bold;
  }
  .ant-table-tbody > tr > td {
    color: #000;
  }
  .el-table thead {
    color: black;
    font-weight: bold;
    background: #fafafa;
  }
  .el-table th.el-table__cell {
    background: #fafafa;
  }
}
::v-deep .ant-table-thead > tr > th {
  color: #000;
  font-weight: bold !important;
}
.ant-col {
  margin: 10px 0;
}

.ant-select {
  width: 60%;
}

.ant-input {
  width: 60%;
}

@media screen and (max-width: 1300px) {
  .el-input {
    width: 70%;
  }

  .el-select {
    width: 70%;
  }

  .app {
    width: calc(100% - 50px);
  }
}

@media screen and (max-width: 1100px) {
  .el-input {
    width: 90%;
  }

  .el-select {
    width: 90%;
  }
}

.table-container {
  width: 100%;
  overflow-x: auto;
  position: relative;

  /* 处理Spin组件层级 */
  ::v-deep .ant-spin-nested-loading {
    overflow: visible !important;
  }

  ::v-deep .ant-spin-container {
    position: static !important;
  }
}

/* 强制表格渲染宽度 */
.ant-table {
  min-width: 2000px !important;

  /* 固定列特殊处理 */
  .ant-table-fixed-columns-in-body {
    visibility: visible !important;
  }
}

/* 强制显示滚动条轨道 */
.table-container {
  scrollbar-width: thin; /* Firefox */

  &::-webkit-scrollbar {
    height: 8px;
    background: #f1f1f1;
  }

  &::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
  }
}
/* 添加表格原生滚动条样式 */
::v-deep .ant-table-body {
  overflow-x: auto !important;
  /* overflow-y: auto !important; */
  /* max-height: 500px; 设置最大高度，超出时显示垂直滚动条 */
}

/* 确保使用原生滚动条样式 */
::v-deep .ant-table-body::-webkit-scrollbar {
  width: 8px !important;
  height: 8px !important;
}

::v-deep .ant-table-body::-webkit-scrollbar-thumb {
  background-color: #c1c1c1 !important;
  border-radius: 4px !important;
}

::v-deep .ant-table-body::-webkit-scrollbar-track {
  background-color: #f1f1f1 !important;
}

/* 修复固定列的问题 */
::v-deep .ant-table-fixed-right {
  right: 8px !important; /* 为滚动条留出空间 */
}
</style>
